﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Biosek
{
	public class DelegateComparer<T> : Comparer<T>
	{
		public DelegateComparer(Comparison<T> c)
		{
			cmp = c;
		}

		Comparison<T> cmp;

		public override int Compare(T x, T y)
		{
			return cmp(x, y);
		}
	}

	public class DelegateEqualityComparer<T> : EqualityComparer<T>
	{
		public DelegateEqualityComparer(Func<T, T, bool> equals, Func<T, int> getHashCode)
		{
			cmp = equals;
			hasher = getHashCode;
		}

		Func<T, T, bool> cmp;
		Func<T, int> hasher;

		public override bool Equals(T x, T y)
		{
			return cmp(x, y);
		}

		public override int GetHashCode(T obj)
		{
			return hasher(obj);
		}
	}
}
